home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / moupp310 / mouse.h < prev    next >
C/C++ Source or Header  |  1992-06-28  |  6KB  |  187 lines

  1. /* -------------------------------------------------------------------- */
  2. /* Mouse++ Version 3.1             mouse.h             Revised 06/28/92 */
  3. /*                                                                      */
  4. /* General mouse class for Turbo C++/Borland C++.                       */
  5. /* Copyright 1991, 1992 by Carl W. Moreland                             */
  6. /* This source code may be freely distributed as long as the copyright  */
  7. /* notice remains intact.                                               */
  8. /* -------------------------------------------------------------------- */
  9.  
  10. #ifndef MOUSEdotH
  11. #define MOUSEdotH
  12.  
  13. #define MOUSE_BUFFER_SIZE 8
  14.  
  15. #define LEFTBUTTON    0       // mouse button assignments
  16. #define RIGHTBUTTON    1
  17. #define CENTERBUTTON    2
  18.  
  19. #define CURSORSOFT    0       // used in struct TextCursor
  20. #define CURSORHARD    1
  21.  
  22. #define MOUSE_MOVED    0x01    // event masks for event handler
  23. #define LB_PRESSED      0x02
  24. #define LB_RELEASED     0x04
  25. #define RB_PRESSED      0x08
  26. #define RB_RELEASED     0x10
  27. #define CB_PRESSED      0x20
  28. #define CB_RELEASED     0x40
  29.  
  30. #define SHIFT_PRESSED   0x08    // key shift masks
  31. #define RSHIFT_PRESSED  0x10
  32. #define LSHIFT_PRESSED  0x20
  33. #define CTRL_PRESSED    0x40
  34. #define ALT_PRESSED     0x80
  35.  
  36. #define EventExit() __emit__(0x5D,0x5F,0x5E,0x1F,0x07,\
  37.                              0x5A,0x59,0x5B,0x58,0xCB);
  38.  
  39. /* -------------------------------------------------------------------
  40. The above emitted code is equivalent to the following assembler code:
  41.  
  42.        pop   bp
  43.        pop   di
  44.        pop   si
  45.        pop   ds
  46.        pop   es   ;interrupt exit processing
  47.        pop   dx
  48.        pop   cx
  49.        pop   bx
  50.        pop   ax
  51.        retf       ;far return
  52.    ------------------------------------------------------------------- */
  53.  
  54. void interrupt MouseHandler(void);
  55.  
  56. struct GraphicsCursor        // structure for graphics cursor (0x09)
  57. {
  58.   unsigned char hotx, hoty;     // hot spot; (0,0) = upper left corner
  59.   unsigned *image;              // 16 x 16 pixel screen and cursor masks
  60. };                // see cursor.h for predefined cursors
  61.  
  62. struct ColorGraphicsCursor    // structure for graphics cursor (0x09)
  63. {
  64.   unsigned char hotx, hoty;     // hot spot; (0,0) = upper left corner
  65.   unsigned *image;            // 16 x 16 pixel screen and color masks
  66. };                // see cursor.h for predefined cursors
  67.  
  68. struct TextCursor               // structure for text cursor (0x0A)
  69. {
  70.   int type;            // hard or soft cursor
  71.   unsigned arg1, arg2;        // screen and cursor masks
  72. };
  73.  
  74. struct OldEventHandler        // structure to save old handler (0x14)
  75. {
  76.   unsigned mask;        // event mask
  77.   unsigned segment, offset;    // address of event handler
  78. };
  79.  
  80. struct MouseInfo        // structure to return data (0x24)
  81. {
  82.   unsigned char type;        // bus=1, serial=2, InPort=3, PS/2=4, HP=5
  83.   unsigned char majorvers;    // software major version
  84.   unsigned char minorvers;    // software minor version
  85.   unsigned char irq;        // IRQ used (2-7), 0 for PS/2
  86. };
  87.  
  88. struct MouseEvent        // event buffer structure
  89. {
  90.   unsigned char event;        // trigger event
  91.   unsigned char button;        // button status
  92.   unsigned int  x, y;        // cursor coordinates
  93.   unsigned int  xcount, ycount;    // mickeys moved since last event
  94.   long time;            // time event occurred
  95. };
  96.  
  97. struct MouseClick        // MultiClick buffer structure
  98. {
  99.   unsigned char count;        // number of clicks
  100.   long time;            // time of last click
  101. };
  102.  
  103. class Mouse
  104. {
  105.   static unsigned char exists;    // 1 if mouse found, 0 if not
  106.   static unsigned char enabled;    // 1 if mouse enabled, 0 if not
  107.   static unsigned char visible;    // keeps track of Hide() & Show()
  108.   static unsigned char buttons; // number of buttons
  109.   static unsigned char button;    // button status
  110.   static int x, y;        // x & y position of cursor
  111.   static int xcount, ycount;    // mickeys moved since last event
  112.   static unsigned char hotx, hoty;    // cursor hot spot coords
  113.   static int oldeventmask;    // oldeventxxx holds info on the event
  114.   static int oldeventseg;    //   handler that was active when Mouse
  115.   static int oldeventoff;    //   was initiated.  Used in restore.
  116.  
  117.   MouseEvent Buffer[MOUSE_BUFFER_SIZE];    // event buffer
  118.   static unsigned char HeadPtr;        // buffer pointer
  119.   static unsigned char TailPtr;        // buffer pointer
  120.   unsigned char eventMask;
  121.   void interrupt (*eventHandler)(void);
  122.   static unsigned char event;        // current event
  123.   static unsigned char handlerInstalled;// event handler flag
  124.  
  125.   MouseClick Click[3];            // MultiClick buffer
  126.   static unsigned clickThreshold;    // MultiClick threshold
  127.  
  128. public:
  129.   Mouse(void);
  130.  ~Mouse(void);
  131.   MouseInfo Info;
  132.  
  133.   unsigned char Exists()  { return exists;  }
  134.   unsigned char Visible() { return visible; }
  135.   unsigned char Buttons() { return buttons; }
  136.   unsigned char Button()  { return button;  }
  137.  
  138.   int  xPos()          { return x;      }
  139.   int  yPos()           { return y;      }
  140.   int  xCount()        { return xcount; }
  141.   int  yCount()        { return ycount; }
  142.   unsigned char LB_Dn()   { return (0x01 & button); }
  143.   unsigned char RB_Dn()   { return (0x02 & button); }
  144.   unsigned char CB_Dn()   { return (0x04 & button); }
  145.  
  146.   void Enable(void);
  147.   void Disable(void);
  148.   void Show(void);
  149.   void Hide(void);
  150.   void Move(int x, int y);
  151.   void Position(void);
  152.   void Motion(void);
  153.   int  Pressed(int mbutton);
  154.   int  Released(int mbutton);
  155.   int  InBox(int left, int top, int right, int bottom);
  156.   void Exclude(int left, int top, int right, int bottom);
  157.   int  MultiClick(int mbutton);
  158.   int  DoubleClick(int mbutton);
  159.   void ClearClick(int mbutton);
  160.  
  161.   void xLimit(int min, int max);
  162.   void yLimit(int min, int max);
  163.   int  GetVideoPage(void);
  164.   void SetVideoPage(int page);
  165.  
  166.   void SetCursor(TextCursor& cursor);
  167.   void SetCursor(GraphicsCursor& cursor);
  168.  
  169.   void SetTextCursor(TextCursor& cursor) { SetCursor(cursor); }
  170.   void SetGraphicsCursor(GraphicsCursor& cursor) { SetCursor(cursor); }
  171.  
  172.   void MickToPix(int horiz, int vert);
  173.   void SetSpeedThreshold(unsigned speed);
  174.   void SetClickThreshold(unsigned time);
  175.  
  176.   void InstallHandler(unsigned mask,
  177.                       void interrupt (*handler)(void) = MouseHandler);
  178.   void ClearHandler(void);
  179.   void Save(int event, int button, int x, int y, int xcount, int ycount);
  180.   void GetEvent(void);
  181.   void ClearEvent(void);
  182.   void ClearBuffer(void);
  183. };
  184.  
  185. extern Mouse mouse;
  186.  
  187. #endif